﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuatToanDAO;
using System.Data;
using System.Data.SqlClient;


public partial class Item : System.Web.UI.Page
{
    public String demo = "";
    public int itemID = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        string strQueryitemID = Request.QueryString["itemID"].ToString();
        string stritemID = strQueryitemID.Substring(strQueryitemID.LastIndexOf('-') + 1);
        itemID = Int16.Parse(stritemID);

        ItemDAO item = new ItemDAO();

        DataSet ds = item.ExecuteSelectFollowItemID(itemID);

        //set Title
        literalHeader.Text = ds.Tables[0].Rows[0]["Name"].ToString();
        lbl_Name.Text = ds.Tables[0].Rows[0]["Name"].ToString();
        lbl_Description.Text = ds.Tables[0].Rows[0]["Description"].ToString();
        if (lbl_Description.Text.Trim() == "")
        {
            lbl_Description.Text = "//Hiện tại chưa có mô tả cho thuật toán này";
        }
        demo = ds.Tables[0].Rows[0]["Demo"].ToString().Trim();

        demo = "~/UserControls/ThuatToan/" + demo;

        if (demo != "" && System.IO.File.Exists(Server.MapPath(demo)))
        {
            UserControl uc = (UserControl)LoadControl(demo);
            view3.Controls.Add(uc);
            lbl_MessageDemo.Visible = false;
        }
        else
        {
            lbl_MessageDemo.Visible = true;
        }


        int viewcount;
        int.TryParse(ds.Tables[0].Rows[0]["ViewCount"].ToString(),out viewcount);
        viewcount = viewcount + 1;

        List<SqlParameter> listparams = new List<SqlParameter>();
        listparams.Add(new SqlParameter("ItemID", itemID));
        listparams.Add(new SqlParameter("ViewCount", viewcount));

        item.ExecuteUpdateViewCount(listparams);

        //Set Tab selected
        int index = 0;
        
        if (ds.Tables[0].Rows[0]["Other1"] !=null)
        {
            string indexSelect = ds.Tables[0].Rows[0]["Other1"].ToString().Trim();
            int.TryParse(indexSelect,out index);

        }
        menuTabs.Items[index].Selected = true ;
        multiTabs.ActiveViewIndex = index;

    }
    protected void menuTabs_MenuItemClick(object sender, MenuEventArgs e)
    {
        multiTabs.ActiveViewIndex = Int32.Parse(menuTabs.SelectedValue);

        //if (menuTabs.SelectedValue == "2")
        //{
        //    demo = "~/UserControls/ThuatToan/SapXep/SapXep.ascx";
        //    if (demo != "" && System.IO.File.Exists(Server.MapPath(demo)))
        //    {
        //        UserControl uc = (UserControl)LoadControl(demo);
        //        view3.Controls.Add(uc);
        //        lbl_Message.Visible = false;
        //    }
        //    else
        //    {
        //        lbl_Message.Visible = true;
        //    }



        //}
    }
   
}